<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="com.jaxplat.commons.Row" %>
<%
    String contextPath = (String) request.getContextPath();
	List hospitalList = (List)request.getAttribute("hospitalList");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
	href="<%=contextPath %>/js/jquery-easyui-1.3/themes/default/easyui.css">
<link rel="stylesheet" href="<%=contextPath %>/css/main.css" type="text/css" />

<link rel="stylesheet" type="text/css"
	href="<%=contextPath %>/js/jquery-easyui-1.3/themes/icon.css">
<script type="text/javascript"
	src="<%=contextPath %>/js/jquery-easyui-1.3/jquery-1.7.2.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath %>/js/jquery-easyui-1.3/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="<%=contextPath %>/js/jquery-easyui-1.3/locale/easyui-lang-zh_CN.js"></script>
<script>


$(function() {
	$('#wndSearch').window({closed:true});
	$.fn.datebox.defaults.formatter = function(date){
		var year = date.getFullYear();
		var month = date.getMonth()+1;
		var day = date.getDate();
		return y+'-'+m+'-'+d;
	}
	$('#start_date').datebox({
		onSelect: function(date)
		{
			var startDate = new Date(date.getFullYear(),date.getMonth(),date.getDate());
			var now = new Date();
			var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
			var diff = (today.getTime() - startDate.getTime())/ 3600 / 1000;

			
			if( diff < 0)
			{
				$.messager.alert('提示','起始日期不能大于今天!','info');
				$('#start_date').datebox('setValue', '');
				$('#start_date').val('');
				return;
			}

			if($('#end_date').val() != '')
			{
				var arr=$('#end_date').val().split("-");
				//var endDate = Date.parse(arrs[0],arrs[1],arrs[2]);
				var endDate = new Date(Date.parse($('#end_date').val().replace(/-/g, "/")));
				var diff2 = (endDate.getTime() - startDate.getTime())/ 3600 / 1000;;
				if( diff2 < 0)
				{
					$.messager.alert('提示','起始日期不能大于结束日期!','info');
					$('#start_date').datebox('setValue', '');
					$('#start_date').val('');
					return;
				}
			}
			$('#start_date').val(startDate.getFullYear()+'-'+(startDate.getMonth()+1)+'-'+startDate.getDate());
		}
	});
	
	$('#end_date').datebox({
		onSelect: function(date)
		{
			var endDate = new Date(date.getFullYear(),date.getMonth(),date.getDate());
			var now = new Date();
			var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());
			var diff = (today.getTime() - endDate.getTime())/ 3600 / 1000;
	
			
			if( diff < 0)
			{
				$.messager.alert('提示','结束日期不能大于今天!','info');
				$('#end_date').datebox('setValue', '');
				$('#end_date').val('');
				return;
			}
			if($('#start_date').val() != '')
			{
				var arr=$('#start_date').val().split("-");
				//var startDate = Date.parse(arrs[0],arrs[1],arrs[2]);
				var startDate = new Date(Date.parse($('#start_date').val().replace(/-/g, "/")));
				var diff2 = (endDate.getTime() - startDate.getTime())/ 3600 / 1000;;
				if( diff2 < 0)
				{
					$.messager.alert('提示','起始日期不能大于结束日期!','info');
					$('#end_date').datebox('setValue', '');
					$('#end_date').val('');
					return;
				}
			}
			$('#end_date').val(endDate.getFullYear()+'-'+(endDate.getMonth()+1)+'-'+endDate.getDate());
		}
	});
	
	$('#dagagrid').datagrid({
		queryParams:{
			hospital_id: $("#hospital_id").combobox('getValue'),
			//section_id: $("#section_id").combobox('getValue'),
			pro_title: $("#pro_title").combobox('getValue'),
			doctor_name: $("#doctor_name").val(),

			id_no: $("#id_no").val(),
			applicant_name: $("#applicant_name").val(),
			mobile_no: $("#mobile_no").val(),
			order_id: $("#order_id").val(),

			apply_type: $("#apply_type").val(),
			start_date: $("#start_date").val(),
			end_date: $("#end_date").val(),
			pay_status: $("#pay_status").combobox('getValue'),
			reserve_status: $("#reserve_status").combobox('getValue')
			},
		title : '预约查询结果',
		nowrap : true,
		autoRowHeight : false,
		striped : true,
		collapsible : false,
		pagination : true,
		rownumbers : true,
		singleSelect :true,
		height : 500,
		pageList: [10,30,50],
		url : '<%=contextPath%>/reserve/reserveMgr.do?method=list',
		sortName : 'order_id',
		sortOrder : 'desc',
		remoteSort : false,
		idField : 'order_id',
		columns : [ [
				{
					field : 'ck',
					checkbox : true
				},
				{
					title : '订单编号',
					field : 'order_id',
					width : 80,
					sortable : true
				},
				{
					field : 'applicant_name',
					title : '用户',
					width : 80
				},
				{
					field : 'mobile_no',
					title : '用户手机号',
					width : 120
				},
				{
					field : 'hospital_name',
					title : '医院',
					width : 100
				},
				{
					field : 'parent_cat_name',
					title : '科&nbsp;&nbsp;&nbsp;室',
					width : 100
				},
				{
					field : 'child_cat_name',
					title : '科室类别',
					width : 100
				},
				{
					field : 'doctor_name',
					title : '医生',
					width : 80
				},
				{
					field : 'reserve_time',
					title : '预约时间',
					width : 90,
				
					sortable : true
				},
				{
					field : 'pay_status',
					title : '支付状态',
					width : 80,
					sortable : true,
					formatter : function(value, data, index) {
						var text = "";
						if(data.pay_status == 1)
						{
							text = "未付费";
						}
						else if(data.pay_status == 2)
						{
							text = "已付费";
						}
						else if(data.pay_status == 3)
						{
							text = "已退费";
						}
						return text;
					}
				},
				{
					field : 'reserve_status',
					title : '预约状态',
					width : 80,
					sortable : true,
					formatter : function(value, data, index) {
						var text = "";
						if(data.reserve_status == 1)
						{
							text = "保留状态";
						}
						else if(data.reserve_status == 2)
						{
							text = "用户取消保留";
						}
						else if(data.reserve_status == 3)
						{
							text = "保留过期";
						}
						else if(data.reserve_status == 4)
						{
							text = "待赴约";
						}
						else if(data.reserve_status == 5)
						{
							text = "取消预约";
						}
						else if(data.reserve_status == 6)
						{
							text = "爽约";
						}
						else if(data.reserve_status == 7)
						{
							text = "已赴约";
						}
						return text;
					}
				},
				{
					field : 'apply_type',
					title : '来源',
					width : 60,

					sortable : true
				},
				{
					field : 'opt',
					title : '操作',
					width : 100,
					align : 'center',
					rowspan : 2,
					formatter : function(value, row) {
						var retText = '<span style="color:red" >';
						retText += '<a href="#" style="cursor:hand;" onclick="viewOrder(\''+row.order_id+'\')">查看</a> &nbsp;';
						retText += '<a href="#" style="cursor:hand;" onclick="refundOrder(\''+row.order_id+'\')">退号</a>';
						retText += '</span>';
						return retText;
					},hidden : true
				}

		] ],
		toolbar : [ {
			id : 'btnequery',
			text : '查看',
			iconCls : 'icon-search',
			handler : function() {
				var rows = $('#dagagrid').datagrid('getSelections'); 
				//判断是否选择行
				if (!rows || rows.length == 0) { 
					$.messager.alert('提示', '请选择需要退号的订单!', 'info'); 
					return; 
				} else {
					if (rows.length == 1) {
						viewOrder(rows[0].order_id);
					} else if (rows.length>1) {
						$.messager.alert('提示', '请选择一条需要退号的订单!', 'info'); 
						return;
					}
			    }
			}
		},{
			id : 'btnereturn',
			text : '退号',
			iconCls : 'icon-undo',
			handler : function() {
				var rows = $('#dagagrid').datagrid('getSelections'); 
				//判断是否选择行
				if (!rows || rows.length == 0) { 
					$.messager.alert('提示', '请选择需要退号的订单!', 'info'); 
					return; 
				} else {
					if (rows.length == 1) {
						refundOrder(rows[0].order_id);
					} else if (rows.length>1) {
						$.messager.alert('提示', '请选择一条需要退号的订单!', 'info'); 
						return;
					}
			    }
			}
		},{
			id : 'btnsearch',
			text : '条件查询',
			iconCls : 'icon-search',
			handler : function() {
				$("#searchForm").form('clear');
				$('#wndSearch').window({
					title:"查询",
					closed:false,
					width : 950,
					height : 200,
					top:($(window).height()-200)*0.5,   
		            left:($(window).width()-950)*0.5,
					modal : true
				});
			}
		}]
	 });
	
 	var cur_pageNumber = 1;
 	var cur_pageSize = 10;

 	var dataUrl = '<%=contextPath%>/reserve/reserveMgr.do?method=list';
	var p = $('#dagagrid').datagrid('getPager');
	$(p).pagination( {

		});	

	// 搜索框中的下拉菜单
	$("#sch_parent_cat").combobox({
		url:'<%=contextPath %>/admin/secCatalogAction.do?method=getParentCatalogs',
		valueField:'id',
		textField:'name',
		onSelect:function(rec)
		{
			var childUrl = '<%=contextPath %>/admin/secCatalogAction.do?method=getCatalogOfParent&id='+rec.id;
			
			$("#sch_child_cat").combobox({
				url: childUrl,
				valueField:'id',
				textField:'name',
				onSelect:function(rec2){
					var childName = rec2.name;
					$("#name").val(childName);
				}
			});
		}
	});
});

function viewOrder(order_id)
{
	document.getElementById("frmDetail").src="<%=contextPath%>/reserve/reserveMgr.do?method=view&order_id="+order_id;	
	$('#wndDetail').window({
		title:"详情",
		closed:false,
		width : 600,
		height : 400,
		top:($(window).height()-400)*0.5,   
        left:($(window).width()-600)*0.5,
		modal : true
	});

}

function refundOrder(order_id)
{
	if(order_id==null || order_id=="")
	{
		return;
	}
	var param = 'orderId='+order_id;
	$.messager.confirm(
					'提示',
					'确定退号?',
					function(result) {
						if (!result) 
						{
							return;
						}
						//提交
						$.post('<%=contextPath%>/reserve/reserveMgr.do?method=refund',
								param,
								function(resp) 
								{
									var response = eval("(" + resp + ")");
									if(response.errcode=='0')
									{
										$.messager.alert('提示','退号成功!','info');
									}
									else
									{
										$.messager.alert('提示',response.message,'info');
									}
								});
					});
	
}

function searchOrder()
{
	$('#dagagrid').datagrid('load',
		{
			hospital_id: $("#hospital_id").combobox('getValue'),
			parent_cat_id: $("#sch_parent_cat").combobox('getValue'),
			child_cat_id: $("#sch_child_cat").combobox('getValue'),
			pro_title: $("#pro_title").combobox('getValue'),
			doctor_name: $("#doctor_name").val(),
	
			id_no: $("#id_no").val(),
			applicant_name: $("#applicant_name").val(),
			mobile_no: $("#mobile_no").val(),
			order_id: $("#order_id").val(),
	
			apply_type: $("#apply_type").val(),
			start_date: $("#start_date").val(),
			end_date: $("#end_date").val(),
			pay_status: $("#pay_status").combobox('getValue'),
			reserve_status: $("#reserve_status").combobox('getValue')
		}
	);
}
function clearForm()
{
	$("#frmSearch").form('clear');
}
</script>
<title>预约管理</title>
</head>
<body >
<div id="wndSearch" class="easyui-window">
<div class="easyui-panel" data-option="fit:true" style="margin:2px 2px">
	<form id="frmSearch" action="">
		<table class="doc-table">
			<tr>
				<td  style="width: 80px;text-align:right;">医院</td>
				<td style="width: 150px;text-align:left;">
					<select id="hospital_id" class="easyui-combobox" readonly="readonly" name="hospital_id" 
							data-options="valueField:'id',textField:'name',url:'<%=contextPath %>/admin/doctorAction.do?method=initHospital'" />
						<option value="">请选择</option>
					</select>
				</td>
				<td style="width: 80px;text-align:right;">申请人证件号</td>
				<td style="width: 150px;text-align:left;">
					<input id="id_no" name="id_no" type="text" class="admin-input" value="" />
				</td>
				<td style="width: 55px;text-align:right;">订单来源</td>
				<td style="width: 250px;text-align:left;">
					<select  id="apply_type" name="apply_type" class="easyui-combobox" style="width:130px;">
						<option value="">请选择</option>
						<option value="wap">WAP</option>
						<option value="ivr">IVR</option>
						<option value="sms">SMS</option>
						<option value="web">WEB</option>
					</select>
				</td>
			</tr>
			<tr>
				<td style="width: 80px;text-align:right;">科室</td>
				<td style="width: 150px;text-align:left;">
					<input id="sch_parent_cat" class="easyui-combobox" name="sch_parent_cat"  style="width:150px;"
						data-options="valueField:'id',textField:'name'" />

					<input type="hidden" id="hd_parent_cat" name="hd_parent_id" value="" />
					<br />
					<input id="sch_child_cat" class="easyui-combobox" name="sch_child_cat" 
									style="width:150px;" 
									data-options="editable:false,valueField:'id',textField:'name',style:{width:150}"/>
							<input type="hidden" id="hd_child_cat" name="hd_child_cat" value="" />
				</td>
				<td style="width: 80px;text-align:right;">申请人</td>
				<td style="width: 150px;text-align:left;">
					<input id="applicant_name" name="applicant_name" type="text" class="admin-input" />
				</td>
				<td style="text-align:right;">预约时间</td>
				<td style="width: 250px;text-align:left;">
					
					<input id="start_date" name="start_date" type="text" class="easyui-datebox" style="width: 100px;" value="" /> 
					-
					<input id="end_date" name="end_date" type="text" class="easyui-datebox" style="width: 100px;" value="" />
				</td>
			</tr>
			<tr>
				<td style="width: 80px;text-align:right;">职称</td>
				<td style="width: 150px;text-align:left;">
					<select id="pro_title" name="pro_title" readonly="readonly" class="easyui-combobox" style="width:130px;">
						<option value="" selected="selected">请选择</option>
						<option value="1">主任医师</option>
						<option value="2">副主任医师</option>
						<option value="3">普通医师</option>
					</select>
				</td>
				<td style="width: 80px;text-align:right;">申请人电话</td>
				<td style="width: 150px;text-align:left;">
					<input id="mobile_no" type="text" class="admin-input" valu="" />
				</td>
				<td style="width:text-align:right;">预约状态</td>
				<td style="width: 250px;text-align:left; ">
					<select id="reserve_status" name="reserve_status" readonly="readonly" class="easyui-combobox" style="width:130px;">
						<option value="" selected="selected">请选择</option>
						<option value="1">保留状态</option>
						<option value="2">用户取消保留</option>
						<option value="3">保留过期</option>
						<option value="4">待赴约</option>
						<option value="5">用户取消预约</option>
						<option value="6">用户爽约</option>
						<option value="7">已赴约</option>
					</select>
					&nbsp;
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="clearForm()">清除</a>
				</td>
			</tr>
			<tr>
				<td style="width: 80px;text-align:right;">医师</td>
				<td style="width: 150px;text-align:left;">
					<input id="doctor_name" name="doctor_name" type="text" class="admin-input" style="width:130px" value=""  />
				</td>
				<td style="width: 80px;text-align:right;">订单编号</td>
				<td style="width: 150px;text-align:left;">
					<input id="order_id" name="order_id" type="text" class="admin-input" />
				</td>
				<td style="text-align:right;">支付状态</td>
				<td style="width: 250px;text-align:left; ">
					<select id="pay_status" name="pay_status" readonly="readonly" class="easyui-combobox" style="width:130px;">
						<option value="">请选择</option>
						<option value="1">未付款</option>
						<option value="2">已付款</option>
						<option value="3">已退款</option>
					</select>
					&nbsp;
					<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="searchOrder()">查询</a>
				</td>
			</tr>
		</table>
	</div>
	</form>
	</div>
	<div class="easyui-panel" data-option="fit:true" style="overflow:auto;">
		<table id="dagagrid" class="easyui-datagrid">
		</table>
	</div>
	
	<div id="wndDetail" class="easyui-window"  data-options="closed:true">
		<iframe id="frmDetail" src="" width="100%" height="370px;"
			frameborder="0" scrolling="no" style="border: 0px none;" ></iframe>
	</div>
</body>
</html>